package com.sweets.look.ui.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sweets.look.R;


public class MarkProgressDialog {
    private final Display display;
    private final Context mContext;
    private Dialog mDialog;
    private TextView mDialogMsg;
    private TextView mDialogTitle;
    private boolean showMsg;
    private boolean showTitle;

    public MarkProgressDialog(Context context) {
        super();
        this.showTitle = false;
        this.showMsg = false;
        this.mContext = context;
        this.display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    }

    public MarkProgressDialog builder() {
        View root = LayoutInflater.from(this.mContext).inflate(R.layout.widget_progress_dialog, (ViewGroup) ((Activity) this.mContext).findViewById(
                android.R.id.content), false);//16908290
        RelativeLayout group = (RelativeLayout) root.findViewById(R.id.dialog_layout);
        this.mDialogTitle = (TextView) root.findViewById(R.id.dialog_title);
        this.mDialogTitle.setVisibility(View.GONE);
        this.mDialogMsg = (TextView) root.findViewById(R.id.dialog_msg);
        this.mDialogMsg.setVisibility(View.GONE);
        this.mDialog = new Dialog(this.mContext, R.style.DialogTheme);
        this.mDialog.setContentView(root);
        int v4 = this.display.getWidth();
        int v0 = this.display.getHeight();
        int v2 = v4 >= v0 ? v0 / 6 * 5 : v4 / 6 * 5;
        group.setLayoutParams(new FrameLayout.LayoutParams(v2, -2));
        this.mDialog.getWindow().setWindowAnimations(R.style.DialogAnimation);
        return this;
    }

    public void dismiss() {
        if(this.mDialog != null && (this.mDialog.isShowing())) {
            this.mDialog.dismiss();
        }
    }

    public MarkProgressDialog setCancelable(boolean cancel) {
        this.mDialog.setCancelable(cancel);
        return this;
    }

    public MarkProgressDialog setCanceledOnTouchOutside(boolean cancel) {
        this.mDialog.setCanceledOnTouchOutside(cancel);
        return this;
    }

    private void setLayout() {
        if(this.showTitle) {
            this.mDialogTitle.setVisibility(View.VISIBLE);
        }

        if(this.showMsg) {
            this.mDialogMsg.setVisibility(View.VISIBLE);
        }
    }

    public MarkProgressDialog setMessage(String msg) {
        this.showMsg = true;
        this.mDialogMsg.setText(((CharSequence)msg));
        return this;
    }

    public MarkProgressDialog setTitle(String title) {
        this.showTitle = true;
        this.mDialogTitle.setText(((CharSequence)title));
        return this;
    }

    public void show() {
        this.setLayout();
        this.mDialog.show();
    }
}

